package com.health;

import java.util.ArrayList;

import com.health.adapter.FragmentAdapter;
import com.health.fragment.admindoc.AdminDocterHealthManage;
import com.health.fragment.admindoc.AdminDocterHome;
import com.health.fragment.admindoc.AdminDocterUpload;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;

/**
 * 主界面【医生管理】
 * 
 * @author nova
 * 
 */
public class MainActivity_Menu_AdminDocter extends NovaFragmentActivity implements OnClickListener {

	private ViewPager viewPager;
	private ArrayList<RadioButton> radioButtons;
	private ArrayList<Fragment> fragments;

	private FragmentAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main_admindoc);
		initView();
		addListener();
	}

	private void initView() {

		viewPager = (ViewPager) findViewById(R.id.viewpager);
		RadioButton doc_home = (RadioButton) findViewById(R.id.rd_doc_home);
		RadioButton doc_health = (RadioButton) findViewById(R.id.rd_doc_healthmanage);
		RadioButton doc_upload = (RadioButton) findViewById(R.id.rd_doc_upload);

		radioButtons = new ArrayList<RadioButton>();
		radioButtons.add(doc_home);
		radioButtons.add(doc_health);
		radioButtons.add(doc_upload);

		doc_home.setOnClickListener(this);
		doc_health.setOnClickListener(this);
		doc_upload.setOnClickListener(this);

		Fragment baseFragement = new AdminDocterHome();
		Fragment cqsf1Fragment = new AdminDocterHealthManage();
		Fragment cqsf2Fragment = new AdminDocterUpload();
		fragments = new ArrayList<Fragment>();
		fragments.add(baseFragement);
		fragments.add(cqsf1Fragment);
		fragments.add(cqsf2Fragment);

		adapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
		viewPager.setAdapter(adapter);
		setChecked(0);
	}

	private void addListener() {

		viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

			}

			@Override
			public void onPageSelected(int position) {
				radioButtons.get(position).setChecked(true);
				setChecked(position);
			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});

	}


	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.rd_doc_home:
			viewPager.setCurrentItem(0);
			setChecked(0);
			break;
		case R.id.rd_doc_healthmanage:
			viewPager.setCurrentItem(1);
			setChecked(1);
			break;
		case R.id.rd_doc_upload:
			viewPager.setCurrentItem(2);
			setChecked(2);
			break;
		default:
			break;
		}

	}


	@SuppressLint("ResourceAsColor")
	private void setChecked(int pos) {
		for (RadioButton rbtn : radioButtons) {
			rbtn.setBackground(null);
		}
		radioButtons.get(pos).setBackgroundResource(R.drawable.rd_chek_center);
	}

//	@Override
//	public void showTJDialog(String text) {
//		// TODO Auto-generated method stub
//		super.showTJDialog(text);
//	}
}
